#include <iostream>
#include <sstream>
#include <string>

class Person {
public:
    std::string name;
    int age;

    // 序列化为字符串
    std::string serializeToString() const {
        std::ostringstream oss;
        oss << name << " " << age;
        return oss.str();
    }

    // 反序列化从字符串
    bool deserializeFromString(const std::string& str) {
        std::istringstream iss(str);
        iss >> name >> age;
        return iss.good();
    }
};

int main() {
    Person p1{"Charlie", 40};
    std::string serialized = p1.serializeToString();
    std::cout << "Serialized: " << serialized << std::endl;

    Person p2;
    if (p2.deserializeFromString(serialized)) {
        std::cout << "Deserialized: " << p2.name << ", " << p2.age << std::endl;
    } else {
        std::cerr << "Deserialization failed!" << std::endl;
    }

    return 0;
}